//二叉搜索树的最小绝对差 
class Solution {
public:
    TreeNode* prev=nullptr;
    int res=INT_MAX;
    int getMinimumDifference(TreeNode* root) 
    {
        inorder(root);
        return res;
    }
    void inorder(TreeNode* root)
    {
        if(root==nullptr) return;
        inorder(root->left);
        if(prev)
        {
            res=min(res,root->val-prev->val);
        }
        prev=root;
        inorder(root->right);
    }
};
//验证二叉搜索树
class Solution {
public:
    TreeNode* prev=nullptr;
    bool isValidBST(TreeNode* root) 
    {
        if(root==nullptr) return true;

        bool left=isValidBST(root->left);

        if(prev!=nullptr && root->val <= prev->val)
        {
            return false;
        }
        prev=root;
        bool right =isValidBST(root->right);
        return left&&right;
    }
};
//二叉搜素树中的搜索
class Solution {
public:
    TreeNode* searchBST(TreeNode* root, int val) 
    {
        if(root==nullptr) return nullptr;
        if(root->val==val) return root;
        
        if(root->val < val) return searchBST(root->right,val);
        if(root->val > val) return searchBST(root->left,val);
        return nullptr;
    }
};